const Koa = require("koa");
// const KoaRouter = require("@koa/router");
const userRouter = require("./router/userRouter");

const app = new Koa();

// 1. 创建路由对象
// const userRouter = new KoaRouter({ prefix: "/users" });

// // 2. 注册路由
// userRouter.get("/", (ctx, next) => {
//   ctx.body = "users list data~";
// });

// userRouter.get("/:id", (ctx, next) => {
//   const id = ctx.params.id;
//   ctx.body = `users list data~${id}`;
// });

// userRouter.post("/", (ctx, next) => {
//   ctx.body = "create user success~";
// });

// userRouter.delete("/:id", (ctx, next) => {
//   const id = ctx.params.id;
//   ctx.body = `delete user success~${id}`;
// });

// userRouter.patch("/:id", (ctx, next) => {
//   const id = ctx.params.id;
//   ctx.body = `update user success~${id}`;
// });

// 3. 注册路由对象
app.use(userRouter.routes()); // 注册路由
app.use(userRouter.allowedMethods()); // 注册路由允许的方法

app.listen(6000, () => {
  console.log("koa server running at http://127.0.0.1:6000");
});
